<?php

namespace app\common\model\kzvote;

use think\Model;


class Complaint extends Model
{

    

    

    // 表名
    protected $name = 'kzvote_complaint';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'status_text',
        'createtime_text',
        'images_list',
    ];
    

    
    public function getStatusList()
    {
        return ['10' => __('Status 10'), '20' => __('Status 20')];
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getCreatetimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['createtime']) ? $data['createtime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    public function setImagesAttr($value)
    {
        return is_array($value) ? implode(',', $value) : $value;
    }

    public function getImagesListAttr($value, $data)
    {
        return is_array($data['images']) ? $data['images'] : ($data['images'] ? explode(',', $data['images']) : []);
    }

    public function user()
    {
        return $this->belongsTo('app\\common\\model\\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


}
